package com.catmiao.ai.config;

import com.catmiao.ai.listener.ChatModelListener;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;
import java.util.List;

@Configuration
public class LLMConfig {

    @Bean(name = "qwen")
    public ChatModel chatModelQwen(){
        String apiKey = System.getenv("BAILIAN_API_KEY");

        return OpenAiChatModel.builder()
                .apiKey(apiKey)
                .modelName("qwen-plus")
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .logResponses(true)
                .logRequests(true)
                .listeners(List.of(new ChatModelListener())) // 监听器
                .maxRetries(5) // 重试次数
                .timeout(Duration.ofSeconds(60)) // 超时时间
                .build();
    }

    @Bean(name = "deepseek")
    public ChatModel chatModelDeepSeek(){
        String apiKey = System.getenv("DEEPSEEK_API_KEY");

        return OpenAiChatModel.builder()
                .apiKey(apiKey)
                .modelName("deepseek-reasoner")
                .baseUrl("https://api.deepseek.com/v1")
                .build();
    }
}
